﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Bettzueche.DampfrossContinuum
{
    /// <summary>
    /// Ein spezielles Tiling für das Zentrumsfeld.<para>
    /// Das Maß fürs Zentrum ist in der Praxis etweder im Intervall [0.0, 0.1[ (Ebene)
    /// oder in [0.4, 0.5[ (Berg). Zwecks Redutierung der Merkmale / Gewichte spezielles
    /// Tiling mit nur zwi Intervallen
    /// </para>
    /// </summary>
    class ZentrumTiling
    {
        public static int TileCount {
            get { return 2; }
        }

        public static int TilingCount {
            get { return 1; }
        }
            

        public ZentrumTiling() {
        }

        /// <summary>
        /// Gets the feature numbers the specified value has.
        /// </summary>
        /// <param name="value">The value.</param>
        /// <returns>
        /// feature number(s) for specified value.<para>
        /// Ebene (val in [0.0, 0.1[) : 0
        /// Berg (val in [0.4, 0.5[) : 1
        /// sonst leeres Array
        /// </para>
        /// </returns>
        public static int[] GetFeatureNumbers(double value) {
            if (value >= 0.0 && value < 0.1)
                return new int[]{0};
            if (value >= 0.4 && value < 0.5)
                return new int[]{1};
            return new int[0];
        }

        /// <summary>
        /// Gets the feature number the specified value has.
        /// </summary>
        /// <param name="value">The value.</param>
        /// <returns>
        /// feature number for specified value.<para>
        /// Ebene (val in [0.0, 0.1[) : 0
        /// Berg (val in [0.4, 0.5[) : 1
        /// sonst <c>Tiling.OutOfBounds</c>
        /// </para>
        /// </returns>
        public static int GetFeatureNumber(double value) {
            if (value >= 0.0 && value < 0.1)
                return 0;
            if (value >= 0.4 && value < 0.5)
                return 1;
            return Bettzueche.RLLibrary.Types.Tiling.OutOfBounds;
        }

        /// <summary>
        /// Gets the medians of the specified partition numbers, that is the midpoint of the sub-interval (feature-range).
        /// </summary>
        /// <param name="features">The feature's indices.</param>
        /// <returns>Dictionary of feature range midpoints with feature index as key.</returns>
        public static Dictionary<int, double> GetMedians(int[] features) {
            Dictionary<int, double> medians = new Dictionary<int, double>();
            for (int i = 0; i < features.Length; i++) {
                int fNum = features[i];
                if (0 == fNum)
                    medians[fNum] = 0.05;
                else if (1 == fNum)
                    medians[fNum] = 0.45;
                else if (fNum < 0)
                    medians[fNum] = Double.NegativeInfinity;
                else
                    medians[fNum] = Double.PositiveInfinity;
            }
            return medians;
        }
    }
}
